<?php
class Controller_Base extends Eren_Controller
{
    public function setView($file)
    {
        parent::setView('header.tpl');
        parent::setView($file);
        parent::setView('footer.tpl');
    }
    
    public function setViewNoHeaderFooter($file)
    {
        parent::setView($file);
    }

    public function logInJump()
    {
        if(Model_User::isSignIn()){
            $this->forward('http://' . HOST . '/');
        }
    }
    
    public function noLogInJump()
    {
        if(!Model_User::isSignIn()){
            $this->forward('http://' . HOST . '/sign/in');
        }
    }
    
    public function notAuthWeb()
    {
        $this->setData('title', '没权限访问');
        $this->setData('content', '您没有访问权限，即将跳转到首页');
        $this->setView('NoAuth.tpl');
        Model_Log::write("没权限访问");
    }
    
    public function notAuthAjax()
    {
        $this->ajaxRet(-1, '没权限');
        Model_Log::write("没权限访问");
    }
    
    public function notExistPage($title, $content)
    {
        $this->setData('title', $title);
        $this->setData('content', $content);
        $this->setView('NoAuth.tpl');
        Model_Log::write($content);
    }
    
    public function ajaxRet($errCode, $errMsg, $arr = array())
    {
    	if($errCode != 0){
    		Model_Log::write("ErrCode:{$errCode},ErrMsg:{$errMsg}");
    	}
        $arr['errCode'] = $errCode;
        $arr['errMsg']  = $errMsg;
        echo json_encode($arr);
    }
    
    public function errExit($trace, $errMsg)
    {
    	echo "System error, try later or send email to Manu Leu.";
    	Model_Log::write($errMsg . "\r\n" . $trace);
    	exit;
    }
}